package com.aistar.controller;

import com.aistar.util.UploadImgUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UploadController {


    @RequestMapping("/test/upload")
    @ResponseBody
    public Map upload(MultipartFile myfile){
        System.out.println("uploadImg.............");
        Map map = new HashMap<>();

        try {
            String imgUrl = UploadImgUtil.upload(myfile.getBytes(),myfile.getOriginalFilename());
            System.out.println(imgUrl);//   http://pygxj7jxw.bkt.clouddn.com/69b7d003-75e7-481f-8053-ec983b506c55.jpg
            map.put("imgUrl", imgUrl);
        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);
        }
        return map;
    }
}
